axios.defaults.baseURL = 'http://api-breakingnews-web.itheima.net'

//请求拦截器
axios.interceptors.request.use(config => {
// Do something before request is sent
// 优化headers，让带有/my的请求头获得token /api的请求头不获得
if(config.url.indexOf('/my') !== -1){

    config.headers.Authorization = localStorage.getItem('token')
}
return config;
},error => {
// Do something with request error
return Promise.reject(error);
});


//响应拦截器
axios.interceptors.response.use(response => {
// Do something before response is sent
// console.log(response);
if(response.data.status === 1 && response.data.message === "身份认证失败！"){
    location.href = '/login.html'
}
return response;
},error => {
// Do something with response error
return Promise.reject(error);
});